/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.p10.miage.gestionnote.model;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

/**
 *
 * @author charleshenzel
 */
public class NotesValidateur {

    private Map<String, String> HashMap;
    private int echelle;

    public NotesValidateur(Map<String, String> HashMap, int echelle) {
        this.HashMap = HashMap;
        this.echelle = echelle;
    }

    public boolean validate(ActionMessages errors) {
        boolean valider = true;
        Set listKeys = HashMap.keySet();
        Iterator iterateur = listKeys.iterator();
        String[] splitArray = null;

        while (iterateur.hasNext()) 
        {
            boolean dispense = false;
            
            Object key = iterateur.next();
            String noteDispense = HashMap.get(key).toString();
            //int idEtudiant = Integer.parseInt(key.toString());
            splitArray = noteDispense.split("_");
            String note = splitArray[0];
            
            if (!(String.valueOf(note).isEmpty())) 
            {
                if(Float.parseFloat(note)>this.echelle)
                {
                    valider = false;
                }
            }
        }
        if(valider==false)
        {
            errors.add("note", new ActionMessage("errors.note", " notes"));
        }

        return valider;

    }
}